<?php
/**
 * Created by PhpStorm.
 * User: Hk
 * Date: 2021/2/4
 * Time: 16:19
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\StoresCate;
use Illuminate\Http\Request;

class StoresCateController extends Controller
{

    public $model;
    public function __construct(){
        $this->model = new StoresCate();
    }

    /**
     * Notes: 列表
     * User: HK
     * Date: 2021/2/4
     * Time: 16:23
     * email: 1919194843@qq.com
     */
    public function index ()
    {
        return $this->success( $this->model->getPaginate(['status' => 1]) );
    }

    /**
     * Notes: 分类添加
     * User: HK
     * Date: 2021/2/4
     * Time: 16:36
     * email: 1919194843@qq.com
     */
    public function store (Request $request)
    {
        $data = $request->post();
        $data['create_time'] = time();
        return $this->model->addInfo( $data ) ? $this->success('添加成功!') : $this->error('添加失败!');
    }

    /**
     * Notes: 展示
     * User: HK
     * Date: 2021/2/4
     * Time: 16:42
     * email: 1919194843@qq.com
     */
    public function show ( $id )
    {
        return $this->success( $this->model->getInfoById( $id ) );
    }

    /**
     * Notes: 修改
     * User: HK
     * Date: 2021/2/4
     * Time: 16:44
     * email: 1919194843@qq.com
     */
    public function update (Request $request)
    {
        $data = $request->post();

        unset($data['create_time']);

        return $this->model->updateById( $data['id'] , $data ) ? $this->success('修改成功!') : $this->error('修改失败!');
    }



    /**
     * Notes: 删除
     * User: HK
     * Date: 2021/1/27
     * Time: 15:23
     * email: 1919194843@qq.com
     * @param $ids
     * @return array
     */
    public function destroy ($ids)
    {
        return $this->model->deleteAll( $ids ) ? $this->success('删除成功!') : $this->error('删除失败!');
    }
}
